package com.piesat.quake.business.device.mqtt;

/**
 * 基本数据类型转换器
 *
 * @author Gersy
 * @date 2023/3/10
 * @since 1.0
 */
public class DataConversion {

    public static void main(String[] args){
        int data=65534;
        short s= int2UnsignedShort(data);
        int i = unsignedShort2Int(s);
        System.out.println(i);
        short b=255;
        byte b1 = short2UnsignedByte(b);
        int i1 = unsignedByte2Short(b1);
        System.out.println(i1);
    }

    public static byte short2UnsignedByte(short b){
        return (byte)( b & 0xFF);
    }

    public static short unsignedByte2Short(byte b){
        return (short) ( b & 0xFF);
    }

    public static short int2UnsignedShort(int b){
        return (short) ( b & 0x0FFFF);
    }

    public static int unsignedShort2Int(short b){
        return b & 0x0FFFF;
    }
}
